using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace MSNClient
{
    public partial class LoginForm : Form
    {
        public LoginForm()
        {
            InitializeComponent();
            tb_account.KeyDown += new KeyEventHandler(KeyDownEvent);
            tb_password.KeyDown += new KeyEventHandler(KeyDownEvent);
            btn_ok.KeyDown +=new KeyEventHandler(KeyDownEvent);
            btn_cancel.KeyDown += new KeyEventHandler(KeyDownEvent);

        }

        void KeyDownEvent(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                btn_ok.PerformClick();
                e.Handled = true;
            }
            else if (e.KeyCode == Keys.Escape)
            {
                btn_cancel.PerformClick();
                e.Handled = true;
            }
        }

        private void btn_ok_Click(object sender, EventArgs e)
        {
            if (!IsAccountOk())
            {
                MessageBox.Show("Incorrect account name:example@example.com");
            }
            else if (tb_password.Text.Length < 1)
            {
                MessageBox.Show("Please enter password!");
            }
            else
            {
                DialogResult = DialogResult.OK;
                Close();
            }
        }
        private bool IsAccountOk()
        {
            if (!tb_account.Text.Contains("@") && !tb_account.Text.Contains("."))
            {
                return false;
            }
            return true;
        }
        private void btn_cancel_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
            Close();
        }
        public String GetPassword
        {
            get { return tb_password.Text; }
        }
        public String AccountName
        {
            get { return tb_account.Text; }
            set { tb_account.Text = value; }
        }
    }
}